#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>

using namespace std;
class Solution 
{
public:
    int timeRequiredToBuy(vector<int>& tickets, int k) 
    {
        int res = 0;
        for (int i = 0; i < tickets.size(); i++)
        {
            if (i <= k)
            {
                res += min(tickets[k], tickets[i]);
            }
            else
            {
                res += min(tickets[k] - 1, tickets[i]);
            }
        }
        return res;
    }
};

int main()
{
    Solution solution;
    vector<int> tickets = { 2, 3, 2 };
    int k = 2;
    int totalTime = solution.timeRequiredToBuy(tickets, k);
    cout << totalTime << endl;

    return 0;
}